package writtenTraining.day24;

import java.util.*;

/**
 * day24:(1)深搜+ 二叉树：JZ79 判断是不是平衡二叉树
 */


class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;
    public TreeNode(int val) {
      this.val = val;
    }
  }




 class Solution {

    public boolean IsBalanced_Solution (TreeNode pRoot) {

        return dfs(pRoot) >= 0 ? true : false;
    }


    private int dfs(TreeNode root) {
        if(root == null) {
            return 0;
        }

        int left = dfs(root.left);
        if(left < 0) {
            return -1;
        }
        int right = dfs(root.right);
        if(right < 0) {
            return -1;
        }

        return Math.abs(right - left) > 1 ? -1 : Math.max(left,right) + 1;
    }


}



/**
 * day24:(2)二维前缀和思想：DP10 最大子矩阵
 */
public class Main {
    public static void main(String[] args) {
        // 前缀和思想

        // 输入数据
        Scanner in =new Scanner(System.in);
        int n = in.nextInt();

        // 创建dp
        int[][] dp = new int[n+1][n+1];
        // 初始化
        // 填表
        int ret = -0x3f3f3f3f;
        for(int i =1 ; i <= n ; i++) {
            for(int j = 1; j <= n; j++) {
                dp[i][j] = dp[i-1][j] + dp[i][j-1] + in.nextInt() - dp[i-1][j-1];
                
                for(int k = 1; k <= i; k++) {
                    for(int u = 1; u <= j; u++) {
                        ret = Math.max(ret,dp[i][j] - dp[k-1][j] 
                        - dp[i][u-1] + dp[k - 1][u - 1]);
                    }
                }
            }
        }
        // 返回值
        System.out.println(ret);
    }
}


/**
 * day24:(3)滑动窗口：小葱的01串
 */


 class Main1 {
    public static void main(String[] agrs) {
//        滑动窗口
        // 输入数据
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        char[] str = in.next().toCharArray();
        int len = str.length;

        int zero = 0, one = 0;
        for(int i =0; i < len; i++) {
//             统计
            if(str[i] == '0') {
                zero++;
            } else if(str[i] == '1') {
                one++;
            }
        }

        if(zero % 2 == 1 || one % 2 == 1) {
            System.out.println(0);
        } else {
            int tZero = zero / 2, tOne = one / 2;
            zero= 0;
            one = 0;
            int ret = 0;

            for(int left = 0, right = 0; left < len ; right++) {
//                 从头开始
                if(right >= len) {
                    right = 0;
                }

                //                 更新结果
                if(tZero == zero && one == tOne) {
                    ret++;
                }


//                 入窗口
                if(str[right] == '0') {
                    zero++;
                } else if(str[right] == '1') {
                    one++;
                }


                //  出窗口
                while(left < len  && (zero > tZero || one > tOne)) {
                    if(str[left] == '0') {
                        zero--;
                    } else if(str[left] == '1') {
                        one--;
                    }
                    left++;
                }




            }

//             输入结果
            System.out.println(ret);
        }
    }
}


/**
 * day24:(3)滑动窗口 + 拿整体的一部分：小葱的01串
 */


 class Main2 {
    public static void main(String[] agrs) {
        // 输入数据
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        char[] str = in.next().toCharArray();
        int len = str.length;

        int zero = 0, one = 0;
        for(int i =0; i < len; i++) {
//             统计
            if(str[i] == '0') {
                zero++;
            } else if(str[i] == '1') {
                one++;
            }
        }

        if(zero % 2 == 1 || one % 2 == 1) {
            System.out.println(0);
        } else {
            int tZero = zero / 2, tOne = one / 2 , half = len / 2;
            zero= 0;
            one = 0;
            int ret = 0;

            for(int left = 0, right = 0; right < len - 1; right++) {



//                 入窗口
                if(str[right] == '0') {
                    zero++;
                } else if(str[right] == '1') {
                    one++;
                }

                // 如果超出窗口就减
                while(right - left + 1 > half) {
                    if(str[left] == '0') {
                        zero--;
                    } else if(str[left] == '1') {
                        one--;
                    }
                    left++;
                }


                if(right - left + 1 == half && zero == tZero
                        && one == tOne) {
                    ret+= 2;
                }

            }

//             输入结果
            System.out.println(ret);
        }
    }
}